<template>
  <main-wrap>
    <div class="my-list-nodata-text" v-show="showNoData">暂无内容</div>
    <van-pull-refresh v-model="refreshing" @refresh="onRefresh" class="wrapper">
      <van-list v-model="loading" :finished="finished" :immediate-check="false" @load="getData" ref="vanList">
        <index-item v-for="item in listData" :key="item.id" :item="item" v-if="(item.stat !== '-1' && item.stat !== '50' && item.stat !== '40')"></index-item>
      </van-list>
    </van-pull-refresh>

    <my-tab-bar :curtab="0"></my-tab-bar>
  </main-wrap>
</template>

<script>
import MainWrap from '@/components/mainWrap'
import MyTabBar from '@/components/mytabbar'
import IndexItem from './indexItem'
export default {
  name: 'Index',
  components: {
    MainWrap,
    MyTabBar,
    IndexItem
  },
  data () {
    return {
      refreshing: true,
      loading: false,
      finished: false,

      listData: [],
      curPage: 1,
      pageSize: this.cm.pageSize,
      totalPage: 1,

      showNoData: false
    }
  },
  mounted () {
    this.cm.overscroll(document.querySelector('.wrapper'))

    this.getData()
  },
  methods: {
    getData () {
      this.cm.myajax('/sys/userrepair/myTask', {
        type: '1',
        limit: this.pageSize,
        page: this.curPage
      }, (data) => {
        this.loading = false
        this.refreshing = false

        if (data.page.list.length === 0) {
          this.finished = true
          if (this.curPage === 1) this.showNoData = true
        } else {
          this.curPage++

          for (let i = 0; i < data.page.list.length; i++) {
            let item = data.page.list[i]
            this.listData.push({
              id: item.repairId,
              tx: this.cm.getAvatar(item.createByUserObj.avatarUrl),
              ty: this.cm.getCategoryStr(item.labelId),
              addr: this.cm.getBuildingStr(item.buildingId) + item.address,
              stat: item.isReceipt,
              reporterdept: item.createByUserObj.deptNames,
              reportername: item.createByUserObj.name,
              reporttime: item.createTime,
              appointtime: (item.repairDate !== null) ? item.repairDate.slice(0, 11) + item.repairBeginTime : ''
            })
          }
        }
      })
    },
    onRefresh () {
      this.curPage = 1
      this.listData = []
      this.finished = false
      this.showNoData = false
      this.getData()
      // this.$nextTick(() => {
      //   this.$refs.vanList.check()
      // })
    }
  }
}
</script>

<style lang="stylus" scoped>
.wrapper >>> .van-pull-refresh__track
  height: calc(100vh - 92px)
.wrapper
  overflow scroll
  padding 20px 15px
</style>
